import 'package:get/get.dart';
import 'package:xin_he/utils/xin_he_UI_constancs.dart';

import '../../../service/xin_he_reqest.dart';
import '../../../utils/xin_he_storage.dart';
import '../../../utils/xin_he_toast.dart';
import '../xin_he_mine_cloud_cha_zi/xin_he_assets_account_list_item_entity.dart';
import '../xin_he_mine_cloud_cha_zi/xin_he_assets_acount_model.dart';
import 'xin_he_mine_cast_fee_redbag_state.dart';

class XinHeMineCastFeeRedbagLogic extends GetxController {
  final XinHeMineCastFeeRedbagState state = XinHeMineCastFeeRedbagState();
  Rx<XinHeAssetsAccountModel> assetsModel = XinHeAssetsAccountModel().obs;
  RxList dataList = [].obs;


  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();

    requestAssetAcount();

    requestAssetDetailByUser();
  }

  requestAssetAcount() async {

    var userId = await XinHeLocalStorage.get(XinHeStorage.userId);
    Map<String,dynamic> ss = {
      'userId':userId,
      'assetType': 'CONSUMER_GOLD_RED_ENVELOPE'
    };

    XinHeRequestDataResult result = await XinHeHttpRequestData.requestUniversalPost(url: '/assetDetailCount/queryAssetCount',params: ss,isPost: false);
    if(!result.result || result.data['code'] != 0) {
      XinHeToast.center(result.data['message']);
      return ;
    }
    Map<String, dynamic> json = result.data['data'];
    XinHeAssetsAccountModel model = XinHeAssetsAccountModel.fromJson(json);
    assetsModel.value = model;
  }

  requestAssetDetailByUser() async {

    var userId = await XinHeLocalStorage.get(XinHeStorage.userId);
    Map<String,dynamic> ss = {
      'userId':userId,
      'assetType': 'CONSUMER_GOLD_RED_ENVELOPE'
    };

    XinHeRequestDataResult result = await XinHeHttpRequestData.requestUniversalPost(url: '/assetDetailCount/queryAssetDetailByUser',params: ss,isPost: false);
    if(!result.result || result.data['code'] != 0) {
      XinHeToast.center(result.data['message']);
      return ;
    }
    List list = result.data['data']??[];
    List modelArr = [];
    if(list.isNotEmpty) {
      for(var e in list) {
        XinHeAssetsAccountListItemEntity model = XinHeAssetsAccountListItemEntity.fromJson(e);
        modelArr.add(model);
      }
      dataList.value = modelArr;
    }
  }

  getTradeString(String type) {

    var str = '';
    switch(type){
      case "ADOPTING_OIL_TEA_TREES":
        str = TradeType.ADOPTING_OIL_TEA_TREES.val;
        break;
      case "ADOPTED_TREE":
        str = TradeType.ADOPTED_TREE.val;
        break;
      case "ADDITIONAL_GIFT_YUN_CHA_SEED":
        str = TradeType.ADDITIONAL_GIFT_YUN_CHA_SEED.val;
        break;

      case "ADOPTED_OIL_CARD":
        str = TradeType.ADOPTED_OIL_CARD.val;
        break;
      case "ADOPTED_OIL_CARD_EXCHANGE_TEA_OIL":
        str = TradeType.ADOPTED_OIL_CARD_EXCHANGE_TEA_OIL.val;
        break;
      case "ADOPTED_CONSUMER_GOLD_RED_ENVELOPE":
        str = TradeType.ADOPTED_CONSUMER_GOLD_RED_ENVELOPE.val;
        break;
      case "SYSTEM_THAW_CONSUMER_GOLD_RED_ENVELOPE":
        str = TradeType.SYSTEM_THAW_CONSUMER_GOLD_RED_ENVELOPE.val;
        break;
      case "TWO_THAW_YUN_CHA_SEED":
        str = TradeType.TWO_THAW_YUN_CHA_SEED.val;
        break;
      case "THREE_THAW_YUN_CHA_SEED":
        str = TradeType.THREE_THAW_YUN_CHA_SEED.val;
        break;

      case "TWO_THAW_REWARD":
        str = TradeType.TWO_THAW_REWARD.val;
        break;
      case "THREE_THAW_REWARD":
        str = TradeType.THREE_THAW_REWARD.val;
        break;
      case "ADDITIONAL_REWARDS":
        str = TradeType.ADDITIONAL_REWARDS.val;
        break;
      case "FOUNDER_REWARDS":
        str = TradeType.FOUNDER_REWARDS.val;
        break;
      case "RECOMMEND_FOUNDER_THAWING":
        str = TradeType.RECOMMEND_FOUNDER_THAWING.val;
        break;
      case "ADDITIONAL_YUN_CHA_SEED":
        str = TradeType.ADDITIONAL_YUN_CHA_SEED.val;
        break;
    }


    return str;


  }

}
